package com.itheima.service.serviceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.dao.CheckItemDao;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    CheckItemDao checkItemDao;

    @Override
    public void addCheckItem(CheckItem checkItem) {
        checkItemDao.addCheckItem(checkItem);
    }

    @Override
    public void deleteCheckItem(String id) {
        checkItemDao.deleteCheckGroupCheckItem(id);

        checkItemDao.deleteCheckItem(id);
    }

    @Override
    public void updateCheckItem(CheckItem checkItem) {
        checkItemDao.updateCheckItem(checkItem);
    }

    @Override
    public CheckItem findByIdCheckItem(String id) {
        CheckItem checkItem = checkItemDao.findByIdCheckItem(id);
        return checkItem;
    }

    @Override
    public PageResult selectPageCheckItem(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());

        List<CheckItem> list = checkItemDao.selectPageCheckItem(queryPageBean.getQueryString());
        Page<CheckItem> p = (Page<CheckItem>) list;

        PageResult pageResult = new PageResult(p.getTotal(), p.getResult());
        return pageResult;
    }
}
